home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ddlnch10 / ddlnch.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  13.6 KB  |  376 lines

  1. VERSION 2.00
  2. Begin Form ddlnch 
  3.    Caption         =   "Drag Drop Launch"
  4.    ClientHeight    =   4380
  5.    ClientLeft      =   2595
  6.    ClientTop       =   2385
  7.    ClientWidth     =   4470
  8.    Height          =   4785
  9.    Icon            =   DDLNCH.FRX:0000
  10.    Left            =   2535
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4380
  13.    ScaleWidth      =   4470
  14.    Top             =   2040
  15.    Width           =   4590
  16.    Begin CommandButton AboutButton 
  17.       Caption         =   "About"
  18.       Height          =   492
  19.       Left            =   2760
  20.       TabIndex        =   4
  21.       Top             =   3240
  22.       Width           =   852
  23.    End
  24.    Begin CommonDialog CMDialog1 
  25.       FontBold        =   -1  'True
  26.       Left            =   2880
  27.       Top             =   3960
  28.    End
  29.    Begin CommandButton ExitButton 
  30.       Caption         =   "Exit"
  31.       Height          =   492
  32.       Left            =   2760
  33.       TabIndex        =   3
  34.       Top             =   2520
  35.       Width           =   852
  36.    End
  37.    Begin CommandButton DoneButton 
  38.       Caption         =   "Done"
  39.       Height          =   492
  40.       Left            =   2760
  41.       TabIndex        =   2
  42.       Top             =   1800
  43.       Width           =   852
  44.    End
  45.    Begin ListBox List1 
  46.       Height          =   2370
  47.       Left            =   600
  48.       TabIndex        =   0
  49.       Top             =   1560
  50.       Width           =   1935
  51.    End
  52.    Begin Label Label1 
  53.       Caption         =   "The INI file did not contain the section you specified on the command line.  The following things are in the INI file.  Please select one of them, or EXIT to quit."
  54.       Height          =   1332
  55.       Left            =   600
  56.       TabIndex        =   1
  57.       Top             =   240
  58.       Width           =   3252
  59.    End
  60. Dim PartialCmds(5) As String
  61. Dim FilePointer As Integer
  62. Dim DirPointer As Integer
  63. Dim DirMask As String
  64. Sub AboutButton_Click ()
  65.     lf$ = Chr$(10)
  66.     MsgBox "Version " + VERSION + lf$ + " Written by Robert Castle CIS 70337,605" + lf$ + "Free Use to All", MB_OK, "Drag Drop Launcher"
  67. End Sub
  68. Sub DDWhatAmI (DDName, DDCmdString, FilePointer, DirPointer, PartialCmds() As String, DirMask, ChgDirFlag)
  69. Dim TempString As String, TempString1 As String
  70. Dim IniPathFile As String
  71. Dim StringLen As Integer
  72. Dim x As Integer, i As Integer, NumItems As Integer
  73. Dim DirMarkerStart As Integer, DirmaarkerEnd As Integer
  74. Dim FileMarkerStart As Integer, FileMarkerEnd As Integer
  75. Dim LDDCmdString As Integer, LDirMask As Integer
  76. 'get from the ini file, what I am supposed to do.
  77. IniPathFile = CurDir$ + "\" + INIFILE       'try current dir
  78. NumItems = GetPrivateProfileInt("Main", "Number", 0, IniPathFile)
  79. If NumItems = 0 Then
  80.     IniPathFile = INIFILE   'let windows try the Windows Dir
  81.     NumItems = GetPrivateProfileInt("Main", "Number", 0, IniPathFile)
  82.     If NumItems = 0 Then
  83.         MsgBox "INI file is invalid or missing", MB_OK, "DDLnch"
  84.         End
  85.     End If
  86. End If
  87. If DDName = "" Then
  88.     'parse the command string
  89.     '
  90.     TempString = Command$
  91.     TempString = DDName
  92. End If
  93. If TempString = "" Then
  94.     'nothing on command string, bring up form
  95.     'make up list box, then exit, form load will take it
  96.     For i = 1 To NumItems
  97.         TempString1 = "Item" + Trim$(Str$(i))
  98.         TempString = Space$(15)
  99.         StringLen = 15
  100.         x = GetPrivateProfileString("Main", TempString1, "", TempString, StringLen, IniPathFile)
  101.         DDLNCH.List1.AddItem Left$(TempString, x)
  102.     Next
  103.     DDName = ""     'this so the form load procedure will know what to do
  104.     Exit Sub
  105. End If
  106. DDName = Trim$(TempString)
  107. TempString = Space$(129)
  108. StringLen = 128
  109. LDDCmdString = GetPrivateProfileString(DDName, "CmdString", " ", TempString, StringLen, IniPathFile)
  110. If LDDCmdString <> 0 Then
  111.     DDCmdString = Left$(TempString, LDDCmdString)
  112.     '
  113.     'nothing found, complain and exit
  114.     '
  115.     MsgBox "Command Line not Found under " + DDName + " in " + IniPathFile, MB_OK, DDName
  116.     End
  117. End If
  118. TempString = Space$(2)
  119. StringLen = 2
  120. x = GetPrivateProfileString(DDName, "ChgDir", "N", TempString, StringLen, IniPathFile)
  121. If x <> 0 Then
  122.     If UCase$(Left$(TempString, 1)) = "Y" Then
  123.         ChgDirFlag = True
  124.     Else
  125.         ChgDirFlag = False
  126.     End If
  127. End If
  128. 'parse the command string.
  129. 'I will parse, and set two pointers up as well as an array of strings.
  130. 'the FilePointer will either be 2,3, or 4, depending on where the file
  131. 'names should be inserted in the command string.
  132. 'the DirPointer will likewise be either 2,3,4 depending on where the destination
  133. 'file is to be inserted.
  134. 'The array of PartialCmds will be filled in with data from the command string
  135. FileMarkerStart = InStr(1, DDCmdString, FileMarker)
  136. FileMarkerEnd = FileMarkerStart + LENFILEMARKER      'FIRST Char AFTER <F>
  137. DirMarkerStart = InStr(1, DDCmdString, DIRMARKER1)
  138. 'note that BOTH dirmarkerEnds may be larger than the length of the string
  139. Debug.Print "FMStart= "; FileMarkerStart; " FMEnd= "; FileMarkerEnd; " DMStart="; DirMarkerStart
  140. If DirMarkerStart <> 0 Then
  141.     DirMarkerEnd = InStr(DirMarkerStart, DDCmdString, DIRMARKER2) + 1'first AFTER <Dxxxxx>
  142.     LDirMask = DirMarkerEnd - DirMarkerStart - LENDIRMARKER1 - LENDIRMARKER2
  143.     Debug.Print " DMEnd = "; DirMarkerEnd
  144.     x = DirMarkerStart + LENDIRMARKER1      'point to start of dirmask
  145.     If DirMarkerEnd = 1 Then                'marker not found
  146.         DirMarkerStart = 0                  'invalid
  147.     ElseIf x >= DirMarkerEnd - 1 Then
  148.         DirMask = "*.*"                     'null length, null dirmask
  149.     ElseIf DirMarkerEnd > x + 2 Then
  150.         DirMask = Mid$(DDCmdString, x, DirMarkerEnd - x - 1)
  151.         If InStr(1, DirMask, ".") = 0 Then
  152.             DirMask = "*.*"
  153.         End If
  154.     Else
  155.         DirMarkerStart = 0                  'something else invalid
  156.     End If
  157. End If
  158. If DirMarkerStart = 0 Then
  159.     x = FileMarkerStart - 1
  160. ElseIf FileMarkerStart = 0 Then
  161.     x = DirMarkerStart - 1
  162. ElseIf DirMarkerStart > FileMarkerStart Then
  163.     x = FileMarkerStart - 1
  164.     x = DirMarkerStart - 1
  165. End If
  166. If x < 1 Then x = LDDCmdString
  167. PartialCmds(1) = Left$(DDCmdString, x)   'first is always the same
  168. If DirMarkerStart = 0 Then      'only a file marker
  169.     If Len(DDCmdString) >= FileMarkerEnd Then
  170.         PartialCmds(3) = Right$(DDCmdString, LDDCmdString - FileMarkerEnd + 1)
  171.     End If
  172.     FilePointer = 2
  173. ElseIf FileMarkerStart = 0 Then
  174.     'only a destination, at most. put files at end
  175.     If Len(DDCmdString) >= DirMarkerEnd Then
  176.         PartialCmds(3) = Right$(DDCmdString, LDDCmdString - DirMarkerEnd + 1)
  177.         FilePointer = 4
  178.     Else
  179.         FilePointer = 3
  180.     End If
  181.     DirPointer = 2
  182. Else                'both file and dir are present
  183.     If FileMarkerEnd < DirMarkerStart Then
  184.         FilePointer = 2 'file entry is first
  185.         If DirMarkerStart > FileMarkerEnd Then
  186.             PartialCmds(3) = Mid$(DDCmdString, FileMarkerEnd, DirMarkerStart - FileMarkerEnd)
  187.             DirPointer = 4
  188.         Else
  189.             DirPointer = 3
  190.         End If
  191.         If Len(DDCmdString) >= DirMarkerEnd Then
  192.             PartialCmds(5) = Right$(DDCmdString, LDDCmdString - DirMarkerEnd + 1)
  193.         End If
  194.     Else
  195.         DirPointer = 2    'dir entry is first
  196.         If FileMarkerStart >= DirMarkerEnd Then
  197.             PartialCmds(3) = Mid$(DDCmdString, DirMarkerEnd, FileMarkerStart - DirMarkerEnd)
  198.             FilePointer = 4
  199.         Else
  200.             FilePointer = 3
  201.         End If
  202.         If Len(DDCmdString) >= FileMarkerEnd Then
  203.             PartialCmds(5) = Right$(DDCmdString, LDDCmdString - FileMarkerEnd + 1)
  204.         End If
  205.     End If
  206. End If
  207. For x = 1 To 5
  208. Debug.Print "Part "; x; " = "; PartialCmds(x)
  209. Debug.Print "FPointer="; FilePointer; " DirPointer="; DirPointer
  210. End Sub
  211. Sub DoneButton_Click ()
  212.     If List1.ListIndex > -1 Then
  213.         DDName = List1.List(List1.ListIndex)
  214.         Form_Load
  215.     End If
  216. End Sub
  217. Sub ExitButton_Click ()
  218.     End
  219. End Sub
  220. Function FileSelect (DirMask As String, FilePath As String) As String
  221. 'put up commondialog and get file name
  222. Dim x As Integer
  223. Dim TempString As String
  224. 'x = InStr(1, DirMask, ".")
  225. 'If x <> 0 Then          'strip all but last
  226. '    TempString = Right$(DirMask, Len(DirMask) - x)
  227. 'Else
  228. '    TempString = DirMask
  229. 'End If
  230. 'If Len(TempString) > 0 And Len(TempString) < 4 Then
  231.     'CMDialog1.DefaultExt = TempString
  232. 'End If
  233. CMDialog1.DialogTitle = DDName
  234. CMDialog1.Flags = MYFLAGSET      'equal to &H8804&
  235. If FilePath <> "" Then
  236.     CMDialog1.InitDir = FilePath
  237.     CMDialog1.InitDir = CurDir$
  238. End If
  239. CMDialog1.Filename = ""
  240. CMDialog1.Filter = DirMask + "|" + DirMask
  241. CMDialog1.Action = DLG_FILE_SAVE
  242. FileSelect = CMDialog1.Filename
  243. End Function
  244. Sub Form_Load ()
  245. Dim wRemoveMsg As Integer
  246. Dim x As Integer, i As Integer, StringLen As Integer
  247. Dim Handle As Integer
  248. Dim NewMessage As Msg
  249. Dim NameOfFile As String * 129
  250. Dim ShortFileName As String
  251. Dim FileList As String, TempString As String
  252. Dim TotFiles As Integer
  253. Dim NewDir As String
  254. Dim ChgDirFlag
  255. ReDim ErrorMessage(31) As String
  256. TotFiles = 0
  257. Const PM_NOREMOVE = 0
  258. Const PM_NOYIELD = 2
  259. 'set up error message strings
  260. ErrorMessage(0) = "Out of Memory"
  261. ErrorMessage(1) = ""
  262. ErrorMessage(2) = "File not found"
  263. ErrorMessage(3) = "Path not found"
  264. ErrorMessage(4) = ""
  265. ErrorMessage(5) = "Attempt to dynamically link to a task"
  266. ErrorMessage(6) = "Library requires separate data segments for each task"
  267. ErrorMessage(7) = ""
  268. ErrorMessage(8) = "Insufficient Memory"
  269. ErrorMessage(9) = ""
  270. ErrorMessage(10) = "Incorrect Windows version"
  271. ErrorMessage(11) = "Invalid EXE file"
  272. ErrorMessage(12) = "O/S 2 App"
  273. ErrorMessage(13) = "DOS 4.0 App"
  274. ErrorMessage(14) = "Unknown .EXE Type"
  275. ErrorMessage(15) = ".EXE created for earlier version of Windows"
  276. ErrorMessage(16) = "Attempt to load 2nd instance (mult data segments)"
  277. ErrorMessage(17) = "Attempt to load 2nd instance (nonshareable DLLs)"
  278. ErrorMessage(18) = "Protected mode app in real mode"
  279. ErrorMessage(19) = "Attempt to load compressed EXE"
  280. ErrorMessage(20) = "DLL required for this app is invalid"
  281. ErrorMessage(21) = "Requires 32 bit extensions"
  282. ErrorMessage(22) = " "
  283. ErrorMessage(23) = " "
  284. ErrorMessage(24) = " "
  285. ErrorMessage(25) = " "
  286. ErrorMessage(26) = " "
  287. ErrorMessage(27) = " "
  288. ErrorMessage(28) = " "
  289. ErrorMessage(29) = " "
  290. ErrorMessage(30) = " "
  291. ErrorMessage(31) = " "
  292. 'get what I'm supposed to do as a result of a DD event
  293. WindowState = MINIMIZED
  294. DDWhatAmI DDName, DDCmdString, FilePointer, DirPointer, PartialCmds(), DirMask, ChgDirFlag
  295. If DDName = "" Then
  296.     WindowState = NORMAL
  297.     Exit Sub
  298. End If
  299. DDLNCH.Visible = True
  300. DDLNCH.Caption = "DD-" + DDName
  301. wRemoveMsg = PM_NOREMOVE Or PM_NOYIELD   'parameters for PeekMessage call
  302. Handle = DDLNCH.hWnd
  303. DragAcceptFiles Handle, True    'identify form as able to accept d/d messages
  304. Do While DoEvents()
  305.     'Dummy = DoEvents()
  306.     x = PeekMessage(NewMessage, Handle, 563, 563, wRemoveMsg) 'determine if a d/d message is waiting
  307.     If x <> 0 Then  'if a dd message is waiting
  308.             'calling DragQueryFile with a -1 value for FileNum returns # of files dropped
  309.         FileNum = -1
  310.         FileList = ""                 'Clear from last call
  311.         x = DragQueryFile(NewMessage.wparam, FileNum, NameOfFile, 128)
  312.             For FileNum = 0 To x - 1   ' for each file dropped
  313.                     'calling with a value greater than -1 returns name of corresponding file
  314.                 StringLen = DragQueryFile(NewMessage.wparam, FileNum, NameOfFile, 128)
  315.                     'add NameOfFile to List
  316.                 ShortFileName = Left$(NameOfFile, StringLen)
  317.                 If ChgDirFlag Then
  318.                     StripandFind ShortFileName, NewDir
  319.                 End If
  320.                 TempString = FileList
  321.                 If FileNum = x - 1 Then 'last file or only one
  322.                     Spacer$ = ""
  323.                 Else
  324.                     Spacer$ = " "
  325.                 End If
  326.                 FileList = TempString + ShortFileName + Spacer$
  327.             Next       'get next file
  328.         DragFinish NewMessage.wparam
  329.         'now build command string and send
  330.         PartialCmds(FilePointer) = FileList
  331.         If DirPointer <> 0 Then       'if command line needs a destination file prompt
  332.             TempString = FileSelect(DirMask, NewDir)
  333.             If TempString = "" Then         'user didn't select anything
  334.                 GoTo LoopON
  335.             Else
  336.                 PartialCmds(DirPointer) = TempString
  337.             End If
  338.         End If
  339.         TempString = PartialCmds(1) + PartialCmds(2) + PartialCmds(3) + PartialCmds(4) + PartialCmds(5)
  340.         Debug.Print TempString
  341.         If ChgDirFlag Then
  342.             ChDir NewDir
  343.         End If
  344.         If Len(TempString) > 128 Then
  345.             MsgBox "Command Line TOO Long. Can't do This.", MB_OK, "DDLnch Message"
  346.         Else
  347.             x = WinExec(TempString, 1)
  348.             If x < 32 Then
  349.                 MsgBox "Error Occurred - " + ErrorMessage(x), MB_OK, "DDLnch Error"
  350.             End If
  351.         End If
  352.     End If
  353. LoopON:
  354. End Sub
  355. Sub List1_DblClick ()
  356.     DoneButton_Click
  357. End Sub
  358. Sub StripandFind (NameOfFile, PathName)
  359. 'strip the file name to base name and put the path in
  360. 'the PathName variable
  361. Dim x, Last_x, Length As Integer
  362. Dim TempStringg As String
  363. Length = Len(NameOfFile)
  364. If Mid$(NameOfFile, 2, 1) = ":" Then
  365.     x = 3
  366.     x = 1
  367. End If
  368. Do While x <> 0
  369.     Last_x = x
  370.     x = InStr(Last_x + 1, NameOfFile, "\")
  371. PathName = Left$(NameOfFile, Last_x - 1)
  372. TempStringg = Right$(NameOfFile, Length - Last_x)
  373. NameOfFile = TempStringg
  374. Debug.Print NameOfFile; PathName
  375. End Sub
  376.